<?php
/**
 * AmplifyCMS
 *
 * This file is part of AmplifyCMS.
 *
 * AmplifyCMS is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * AmplifyCMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Rodrigo Rutkoski Rodrigues, <rutkoski@gmail.com>
 * @copyright Copyright 2008 Rodrigo Rutkoski Rodrigues
 */

/**
 * Menu Item.
 *
 * @author Rodrigo Rutkoski Rodrigues, <rutkoski@gmail.com>
 */
class MenuItem
{

  /**
   *
   * @var string
   */
  public $name;

  /**
   *
   * @var string
   */
  public $label;

  /**
   *
   * @var string
   */
  public $url;

  /**
   *
   * @var string
   */
  public $regex;

  /**
   *
   * @var Menu
   */
  public $submenu;

  /**
   * Constructor.
   *
   * @param $name string
   * @param $label string
   * @param $url string
   * @param $regex string
   * @param $submenu Menu
   * @return void
   */
  public function __construct($name, $label, $url = null, $regex = null, $submenu = null)
  {
    $this->name = $name;
    $this->label = $label;
    //$this->url = url_is_absolute($url) ? $url : Context::getInstance()->getResponse()->makeUrl($url);
    $this->url = $url;
    $this->regex = $regex;
    $this->submenu = $submenu;// ? $submenu : new Menu();
  }

  /**
   * Match $url against regular expression.
   *
   * @param $url string The url to match.
   * @param $true Return value if match.
   * @param $false Return value if not match.
   * @return mixed
   */
  public function match($url, $true = true, $false = '')
  {
    return preg_match($this->regex, $url) ? $true : $false;
  }
}

?>